package br.quest.activities;

import android.os.Bundle;
import android.view.Window;
import br.quest.R;
import br.quest.gps.GPS;
import br.quest.gps.WaypointListener;
import br.quest.maps.RouteOverlay;
import br.quest.models.Route;
import br.quest.models.Waypoint;
import br.quest.utils.Utils;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

/**
 * That's the most important activity: it's the one showing the map with the route being drawn.
 * @author Rodrigo
 */
public class RouteActivity extends MapActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.run_route);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
        //TextView txtTitulo = (TextView) findViewById(R.id.labelTitle);
        //txtTitulo.setText(Constants.APP_TITLE + " - Route");
        
        GPS.configure(this);
        final MapView map = (MapView) findViewById(R.id.mapRunRoute);
        final Route route = new Route("Teste");
        map.getOverlays().add(new RouteOverlay(route, map));
        map.setAlwaysDrawnWithCacheEnabled(true);
        map.setBuiltInZoomControls(true);
        GPS.getInstance().startReading(new WaypointListener() {
            @Override
            public void onWaypointRead(Waypoint point) {
                route.addWaypoint(point);
                Utils.showShortToast(RouteActivity.this, point.getGeoPoint().toString());
                map.getController().animateTo(point.getGeoPoint());
            }
        });
    }
    
    @Override
    protected boolean isRouteDisplayed() {
        return true;
    }

}
